package wyc;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import util.content.ContentSpider;
import util.publish.PublishContent;
import util.publish.TagMake;
import util.publish.TagURL;

public class SpiderFire {

	/**
	 * 
	 */

	public static void main(String[] args) {
		// 读取xml
		//声明参数变量
		String dBName = null;
		String dBHost = null;
		String guid = null;
		String wordHost = null;
		String wordDBName = null;
		String wpHost = null;
		String wpDataBaseName = null;
		String contentEnding = null;
		String titleTrimRexContent = null;
		String sourceNet = null;
		int repeatTimesContent = 0;
		int intervalContent = 0;
		String author_date = null;
		SAXBuilder builder = new SAXBuilder(false);
		List sourceSiteParameterList = null;
		try {
			Document doc = builder.build("spiderParameter.xml");
			Element parameter = doc.getRootElement();
			sourceSiteParameterList = parameter.getChildren("sourceSite");
			for (Iterator iter = sourceSiteParameterList.iterator(); iter.hasNext();) {
				Element sourceSiteParameter = (Element) iter.next();
				dBName = sourceSiteParameter.getChildTextTrim("dBName");
				dBHost = sourceSiteParameter.getChildTextTrim("host");
				wordHost = sourceSiteParameter.getChildTextTrim("wordHost");
				wordDBName = sourceSiteParameter.getChildTextTrim("wordDBName");
				wpHost = sourceSiteParameter.getChildTextTrim("wpHost");
				wpDataBaseName = sourceSiteParameter.getChildTextTrim("wpDataBaseName");
				contentEnding = sourceSiteParameter.getChildTextTrim("contentEnding");
				titleTrimRexContent = sourceSiteParameter.getChildTextTrim("titleTrimRexContent");
				author_date = sourceSiteParameter.getChildTextTrim("author_date");
				sourceNet = sourceSiteParameter.getChildTextTrim("sourceNet");
				repeatTimesContent = Integer.parseInt(sourceSiteParameter.getChildTextTrim("repeatTimesContent"));
				intervalContent = Integer.parseInt(sourceSiteParameter.getChildTextTrim("intervalContent"));
				/*
				//测试代码
				System.out.println(dBName);
				System.out.println(dBHost);
				System.out.println(wordHost);
				System.out.println(wordDBName);
				System.out.println(wpHost);
				System.out.println(wpDataBaseName);
				System.out.println(contentEnding);
				System.out.println(titleTrimRexContent);
				System.out.println(author_date);
				System.out.println(sourceNet);
				System.out.println(repeatTimesContent);
				System.out.println(intervalContent);
				System.out.println(cutLine);*/
			}
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		//抓取网页
		ContentSpider contentGetter = new ContentSpider();		
		contentGetter.setdBName(dBName);
		contentGetter.setHost(dBHost);	
		contentGetter.setWordDBName(wordDBName);
		contentGetter.setWordhost(wordHost);
		contentGetter.setAuthor_date(author_date);
		contentGetter.setContentEnding(contentEnding);
		contentGetter.setIntervalContent(intervalContent);
		contentGetter.setRepeatTimesContent(repeatTimesContent);
		contentGetter.setSourceNet(sourceNet);
		contentGetter.setTitleTrimRexContent(titleTrimRexContent);
		
		// 发布文章
		PublishContent pc = new PublishContent();
		pc.setSourceNet(sourceNet);
		pc.setDBName(dBName);
		pc.setHost(dBHost);
		pc.setWpDataBaseName(wpDataBaseName);
		pc.setWpHost(wpHost);
		pc.setGuid(guid);
		// 生成tag
		TagMake tm = new TagMake();
		tm.setDBName(dBName);
		tm.setHost(dBHost);
		// 发布tag
		TagURL tu = new TagURL();
		tu.setSourceNet(sourceNet);
		tu.setDBName(dBName);
		tu.setHost(dBHost);		
		}
	}

